# 设置执行策略以允许脚本运行
Set-ExecutionPolicy Bypass -Scope Process -Force

# 安装 Chocolatey（如果尚未安装）
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
    Write-Host "Installing Chocolatey..."
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}

# 刷新环境变量以确保 Chocolatey 的路径已添加到系统的 PATH 中
refreshenv

# 安装最新版本的 Python
Write-Host "Installing latest version of Python..."
choco install python --yes

# 安装最新版本的 OpenJDK (Java)
Write-Host "Installing latest version of OpenJDK (Java)..."
choco install openjdk --yes

# 安装最新版本的 Node.js (JavaScript)
Write-Host "Installing latest version of Node.js (JavaScript)..."
choco install nodejs --yes

# 安装最新版本的 .NET SDK (C#)
Write-Host "Installing latest version of .NET SDK (C#)..."
choco install dotnet-sdk --yes

# 验证安装
function Test-Installation {
    param (
        [string]$command,
        [string]$package
    )
    if (Get-Command $command -ErrorAction SilentlyContinue) {
        Write-Host "$package installed successfully."
    } else {
        Write-Host "Failed to install $package. Please check the installation logs."
    }
}

Test-Installation -command 'python' -package 'Python'
Test-Installation -command 'java' -package 'Java'
Test-Installation -command 'node' -package 'Node.js'
Test-Installation -command 'dotnet' -package '.NET SDK'

# 输出版本信息
Write-Host "Installed versions:"
python --version
java -version
node -v
dotnet --version

Write-Host "All installations completed."